package com.homework.内部类;

import java.io.Serializable;
import java.util.Arrays;

public class Car implements Serializable {
  private String brand, model, color;
  private Tires[] tires;
  private int speed;

  public Car(String brand, String model, String color, Tires[] tires) {
    this.brand = brand;
    this.model = model;
    this.color = color;
    this.tires = tires;
    this.speed = tires[0].getDiameter() * 5;
  }

  @Override
  public String toString() {
    return "Car{" +
            "brand='" + brand + '\'' +
            ", model='" + model + '\'' +
            ", color='" + color + '\'' +
            ", speed=" + speed +
            ", tires=" + Arrays.toString(tires) +
            '}';
  }

  public void run() {
    Tires.roll();
    System.out.println("汽车正在跑");
  }

  static class Tires implements Serializable {
    private String brand;
    private int diameter;

    public Tires(String brand, int diameter) {
      this.brand = brand;
      this.diameter = diameter;
    }

    public String getBrand() {
      return brand;
    }

    public void setBrand(String brand) {
      this.brand = brand;
    }

    public int getDiameter() {
      return diameter;
    }

    public void setDiameter(int diameter) {
      this.diameter = diameter;
    }

    public static void roll() {
      System.out.println("四个轮子在跑，滋啦滋啦...");
    }

    @Override
    public String toString() {
      return "Tires{" +
              "brand='" + brand + '\'' +
              ", diameter=" + diameter +
              '}';
    }
  }

  public static void main(String[] args) {
    Tires[] tires = new Tires[4];
    for (int i = 0; i < tires.length; i++) {
      tires[i] = new Tires("米其林", 60);
    }
    Car car = new Car("奥迪", "A6", "白色", tires);
    System.out.println(car);
    car.run();
  }
}
